import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Shapes 1.15
import QtQuick.Layouts 1.15
import QtQuick.VirtualKeyboard 2.1
import QtQuick.VirtualKeyboard.Settings 2.1

MainView {
    id: root
    width: 800
    height: 391
    property color btnColor: "#7080C0"
    property int btnHeight: 30
    property string itemName:""
    property string itemValue:""
    property int lastViewIndex: 0
    property string lastViewUrl:""
    property int lastButtonIndex: 0
    property TextInput textInput:null
    property real maximum: 999999
    property real minimum: 0
    property Rectangle lastRec:null
    property bool isNumber:false
    property bool isDecimal:true;
    function clearText(){
        txtInputValue.text ="";
    }
    Component.onCompleted: {
        VirtualKeyboardSettings.wordCandidateList.alwaysVisible = true
        VirtualKeyboardSettings.activeLocales = ["en_US","zh_CN"]
    }

    Rectangle{
        width:800
        height: 120
        color:"transparent"
            GridLayout{
                anchors.centerIn: parent
                columns: 4
                rows:3

                Button
                {
                    Layout.row:0
                    Layout.column:0
                    Layout.preferredWidth: 100
                    Layout.preferredHeight: btnHeight
                    // x: 152
                    // y: 13
                    text: qsTr("输入项")
                    font.pixelSize: 20
                    background: Rectangle{
                        color: btnColor
                            }
                    onClicked: {
                        // miniKeyBoard.lineValue = "";
                        // miniKeyBoard.textInput=oldPwd;
                    }
                }

                Rectangle {
                    id: recItemName
                    width:300
                    height:25
                    // x: 218
                    // y: 7
                    color: "transparent"
                    border.width: 0
                    border.color: "white"
                    Layout.row:0
                    Layout.column:1
                    Layout.preferredWidth: 300
                    Layout.preferredHeight: 25
                    // 绘制一条边框
                    Shape {
                        anchors.fill: parent
                        ShapePath {
                            strokeWidth: 3
                            strokeColor: "white"
                            strokeStyle: ShapePath.SolidLine
                            startX: 0
                            startY: recItemName.height
                            PathLine {
                                x: recItemName.width
                                y: recItemName.height
                            }
                        }
                    }
                    TextInput{
                        id:oldPwd
                        anchors.fill: parent
                        //echoMode: TextInput.Password
                        color:"white"
                        font.pixelSize: 25
                        horizontalAlignment: Text.AlignHCenter
                        verticalAlignment: Text.AlignBottom
                        text:itemName
                        MouseArea {
                               anchors.fill: parent
                               onClicked: {
                                   //miniKeyBoard.lineValue = "";
                                   //miniKeyBoard.textInput=oldPwd;
                               }
                           }

                    }
                }
                Button
                {
                    // x: 151
                    // y: 51
                    Layout.row:1
                    Layout.column:0
                    Layout.preferredWidth: 100
                    Layout.preferredHeight: btnHeight
                    text: qsTr("当前值")
                    font.pixelSize: 20
                    background: Rectangle{
                        color: btnColor
                            }
                    onClicked: {
                        // miniKeyBoard.lineValue = "";
                        // miniKeyBoard.textInput=newPwd;
                    }
                }
                Rectangle {
                    Layout.row:1
                    Layout.column:1
                    //Layout.preferredWidth: buttonWidth
                    Layout.preferredHeight: 25
                    id: recNewPwd
                    width:300
                    height:30
                    x: 217
                    y: 44
                    color: "transparent"
                    border.width: 0
                    border.color: "white"
                    // 绘制一条边框
                    Shape {
                        anchors.fill: parent
                        ShapePath {
                            strokeWidth: 3
                            strokeColor: "white"
                            strokeStyle: ShapePath.SolidLine
                            startX: 0
                            startY: recNewPwd.height
                            PathLine {
                                x: recNewPwd.width
                                y: recNewPwd.height
                            }
                        }
                    }
                    TextInput{
                        id:newPwd
                        color:"white"
                        anchors.fill: parent
                        //echoMode: TextInput.Password
                        text:itemValue
                        font.pixelSize: 25
                        horizontalAlignment: Text.AlignHCenter
                        verticalAlignment: Text.AlignBottom
                        MouseArea {
                               anchors.fill: parent
                               onClicked: {
                                   // miniKeyBoard.lineValue = "";
                                   // miniKeyBoard.textInput=newPwd;
                               }
                           }
                    }
                }

                Button
                {
                    // x: 131
                    // y: 87
                    Layout.row:2
                    Layout.column:0
                    Layout.preferredWidth: 100
                    Layout.preferredHeight: btnHeight
                    text: qsTr("输入值")
                    font.pixelSize: 20
                    background: Rectangle{
                        color: btnColor
                            }
                    onClicked: {
                        // miniKeyBoard.lineValue = "";
                        // miniKeyBoard.textInput=confirmPwd;
                    }
                }
                Rectangle {
                    id:recConfirmPwd
                    // x: 217
                    // y: 84
                    Layout.row:2
                    Layout.column:1
                    //Layout.preferredWidth: buttonWidth
                    Layout.preferredHeight: 25
                    width:300
                    height:30
                    color: "transparent"
                    border.width: 0
                    border.color: "white"
                    // 绘制一条边框
                    Shape {
                        anchors.fill: parent
                        ShapePath {
                            strokeWidth: 3
                            strokeColor: "white"
                            strokeStyle: ShapePath.SolidLine
                            startX: 0
                            startY: recConfirmPwd.height
                            PathLine {
                                x: recConfirmPwd.width
                                y: recConfirmPwd.height
                            }
                        }
                    }
                   TextInput
                    {
                        anchors.fill: parent
                        id:txtInputValue
                        color: "white"
                        font.pixelSize: 25
                        horizontalAlignment: Text.AlignHCenter
                        verticalAlignment: Text.AlignBottom
                        focus:root.visible
                        InputPanel {
                            id: inputPanel
                            z: 89
                            y: parent.height - inputPanel.height - 60
                            x: 0
                            width: parent.width
                            visible: root.visible
                        }
                    }
                }
                Button
                {
                    id:btnEnterNumberOK
                    //x: 675
                    //y: 20
                    Layout.row:0
                    Layout.column:2
                    Layout.preferredWidth: 100
                    Layout.preferredHeight: 100
                    Layout.rowSpan: 3
                    //width: 100
                    //height: 100
                    background: Rectangle{
                        border.width: 0
                        color: "#C070B0"
                            }

                    text: qsTr("确定")
                    font.pixelSize: 25
                    palette.buttonText: "white"
                    //Connections {
                    //    target: btnEnterNumberOK
                        onClicked: {
//
                            //bottomBar.selected=lastButtonIndex
                            //myLoader.setsource=lastViewUrl
                            if(textInput!=null)
                            {
                                if(isNumber){
                                    var value= Number(txtInputValue.text)
                                    if(value<minimum)
                                    {
                                        value =minimum
                                    }
                                    if(value>maximum)
                                    {
                                        value = maximum
                                    }
                                    textInput.text = value.toString()
                                }
                                else{
                                    textInput.text = txtInputValue.text
                                }
                            }
                            //miniKeyBoard.buttonClean()
                            txtInputValue.text=""
                            root.visible=false
                            if(lastRec!=null){
                                lastRec.visible = true;
                            }
                            //rectangle.selectedView = lastViewIndex
                        }
                    //}
                }
                Button
                {
                    id:btnEnterNumberReturn
                    //x: 675
                    //y: 20
                    Layout.row:0
                    Layout.column:3
                    Layout.preferredWidth: 100
                    Layout.preferredHeight: 100
                    Layout.rowSpan: 3
                    //width: 100
                    //height: 100
                    background: Rectangle{
                        border.width: 0
                        color: "#B0B0D0"
                            }

                    text: qsTr("返回")
                    font.pixelSize: 25
                    palette.buttonText: "white"
                    //Connections {
                    //    target: btnEnterNumberReturn
                        onClicked: {
                            //miniKeyBoard.buttonClean()
                            //rectangle.selectedView = lastViewIndex
                            //bottomBar.selected=lastButtonIndex
                            root.visible=false
                            if(lastRec!=null){
                                lastRec.visible = true;
                            }
                            txtInputValue.text=""
                        }
                    //}
                }
            }
    }
//    MiniKeyBoard1
//    {
//        id: miniKeyBoard
//        x: 0
//        y: 126
//        width: 800
//        isNumber: root.isNumber;
//        textInput: txtInputValue
//    }

}


